#!/usr/bin/env python
# -*- coding: UTF-8 -*-
"""
@Project : SIM7600CE-REST
@File    : main.py
@Author  : Mr.Cai
@Date    : 2024/01/22 21:00
"""

import uvicorn
from fastapi import FastAPI
from fastapi.staticfiles import StaticFiles

from app import errors, middleware
from app.config import appSettings
from app.router import RegisterRouterList

# 实例化FastAPI服务
# redoc_url=None: 代表关闭redoc文
# docs_url=None: 代表关闭SwaggerUi
server = FastAPI(redoc_url=None, docs_url="/apidoc", title="SIM for Python")

# 静态文件
server.mount("/static", StaticFiles(directory="app/static"), name="static")
# 注册自定义错误处理器
errors.registerCustomErrorHandle(server)
# 注册中间件
middleware.registerMiddlewareHandle(server)
# 加载路由
for item in RegisterRouterList:
    server.include_router(item.router)

print("appSettings:", appSettings)

if __name__ == "__main__":
    
    # 使用 python main.py 启动服务
    uvicorn.run(server, host=appSettings.app_host, port=appSettings.app_port)
